# test_db.py
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bank_system.settings')  # 替换为实际 settings 路径
django.setup()
from django.db import connection

try:
    with connection.cursor() as cursor:
        cursor.execute("SELECT 1")
        print("数据库连接成功！")
except Exception as e:
    print(f"数据库连接失败: {e}")